/**
 * @param {string} num1
 * @param {string} num2
 * @return {string}
 */
var addStrings = function(num1, num2) {
  let result = "", flag = false, i, j;
  for(i = num1.length - 1, j = num2.length - 1; i >= 0 && j >= 0; i--, j--) {
    let res = parseInt(num1[i]) + parseInt(num2[j]);
    if(flag) {
      flag = false;
      res += 1;
    }
    if(res >= 10) {
      res -= 10;
      flag = true;
    }
    result = res.toString() + result;
  }
  while(i >= 0) {
    let res = parseInt(num1[i]);
    if(flag) {
      flag = false;
      res += 1;
    }
    if(res >= 10) {
      res -= 10;
      flag = true;
    }
    result = res.toString() + result;
    i--;
  }
  while(j >= 0) {
    let res = parseInt(num2[j]);
    if(flag) {
      flag = false;
      res += 1;
    }
    if(res >= 10) {
      res -= 10;
      flag = true;
    }
    result = res.toString() + result;
    j--;
  }
  if(flag) return "1" + result;
  return result;
};
let num1 = "11", num2 = "123";
console.log(addStrings(num1, num2));
num1 = "456", num2 = "77";
console.log(addStrings(num1, num2));
num1 = "0", num2 = "0";
console.log(addStrings(num1, num2));
num1 = "9333852702227987", num2 = "85731737104263";
console.log(addStrings(num1, num2));
